/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package presentation.proportional;

import customGuiControl.ImagePanel;
import customGuiControl.Listner.wizardRollOverListner;
import customGuiControl.RoundedPanel2;
import customGuiControl.roundedPanel;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.border.Border;

/**
 *
 * @author Quirino
 */
public class Utility {
    
    public static ImageIcon getResizedImageIcon(String pathImg, int widthImg, int heightImg){
        
        ImageIcon imgIcon= null;
        BufferedImage image= null;
        
        String path= System.getProperty("user.dir") + "/src/images/" + pathImg;
        try {
            image = ImageIO.read(new File(path));
        } catch (IOException ex) {
            Logger.getLogger(Utility.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        ImageIcon icon = new ImageIcon();   
        icon.setImage(image);
        Image i = icon.getImage();
        if(i != null){
           imgIcon = new ImageIcon(i.getScaledInstance( widthImg, heightImg, Image.SCALE_SMOOTH));
        }
        
        return imgIcon;
        
    }
    
    public static Dimension getDimensionBacheca(){
        
        Dimension d= new Dimension();
        
        int widthPanelBacheca= gui.getIstance().getPanelBachecaContainer().getWidth();
        int heightPanelBacheca= gui.getIstance().getPanelBachecaContainer().getHeight();
        
        d.setSize(widthPanelBacheca, heightPanelBacheca);
        
        return d;
        
    }
    
    public static void addFindButton(GridBagConstraints gbc, RoundedPanel2 rp, MouseListener m, gui instance){
        
        JPanel cerca = new JPanel();
        cerca.setOpaque(false);
        Border border=BorderFactory.createMatteBorder(0,0,0,2,new Color(128,128,128));
        rp.add(cerca, gbc);
        cerca.setLayout(new relativeMarginLayout(10f, 5f, 5f, 5f));
        ImagePanel cercaIcon=new ImagePanel("src/images/cerca_1.png");
        wizardRollOverListner cercaRoll=new wizardRollOverListner(
                                    "src/images/cerca_1.png",
                                    "src/images/cerca_1.png",
                                    "src/images/cerca_1.png", instance, "Seleziona per effettuare una ricerca");
        cercaRoll.setFrameParent(instance);
        cercaIcon.addMouseListener(cercaRoll);
        cercaIcon.addMouseListener(m);
        cercaIcon.setParent(rp);
        cerca.add(cercaIcon);
        
    }
    
    public static void addAnnullaButton(GridBagConstraints gbc, RoundedPanel2 rp, MouseListener m, gui instance){

        JPanel annulla = new JPanel();
        annulla.setOpaque(false);
        Border border=BorderFactory.createMatteBorder(0,0,0,2,new Color(128,128,128));
        rp.add(annulla, gbc);
        annulla.setLayout(new relativeMarginLayout(10f, 5f, 5f, 5f));
        ImagePanel annullaIcon=new ImagePanel("src/images/annulla_1.png");
        wizardRollOverListner annullaRoll=new wizardRollOverListner(
                                    "src/images/annulla_1.png",
                                    "src/images/annulla_1.png",
                                    "src/images/annulla_1.png", instance, "Seleziona per annullare l'operazione");
        annullaRoll.setFrameParent(instance);
        annullaIcon.addMouseListener(annullaRoll);
        annullaIcon.addMouseListener(m);
        annullaIcon.setParent(rp);
        annulla.add(annullaIcon);
        
    }
    
    public static void addFindBachecaButton(GridBagConstraints gbc, RoundedPanel2 rp, MouseListener m, gui instance){
        
        JPanel cercaBacheca = new JPanel();
        cercaBacheca.setOpaque(false);
        Border border=BorderFactory.createMatteBorder(0,0,0,2,new Color(128,128,128));
        rp.add(cercaBacheca, gbc);
        cercaBacheca.setLayout(new relativeMarginLayout(10f, 5f, 5f, 5f));
        ImagePanel cercaIcon=new ImagePanel("src/images/cercaBacheca.png");
        wizardRollOverListner cercaRoll=new wizardRollOverListner(
                                    "src/images/cercaBacheca.png",
                                    "src/images/cercaBachecaOver.png",
                                    "src/images/cercaBachecaPressed.png", instance, "Seleziona per cercare nella bacheca");
        cercaRoll.setFrameParent(instance);
        cercaIcon.addMouseListener(cercaRoll);
        cercaIcon.addMouseListener(m);
        cercaIcon.setParent(rp);
        cercaBacheca.add(cercaIcon);
        
    }
    
    public static void addModificaProfiloButton(GridBagConstraints gbc, RoundedPanel2 rp, MouseListener m, gui instance){
        
        JPanel pannello = new JPanel();
        pannello.setOpaque(false);
        rp.add(pannello, gbc);
        pannello.setLayout(new relativeMarginLayout(10f, 5f, 5f, 5f));
        ImagePanel pannelloIcon= new ImagePanel("src/images/modificaProfilo.png");
        wizardRollOverListner pannelloRoll=new wizardRollOverListner(
                                                    "src/images/modificaProfilo.png",
                                                    "src/images/modificaProfilo.png",
                                                    "src/images/modificaProfilo.png", instance, "Seleziona per modificare il tuo profilo");
        pannelloRoll.setFrameParent(instance);
        pannelloIcon.addMouseListener(pannelloRoll);
        pannelloIcon.addMouseListener(m);
        pannelloIcon.setParent(rp);
        pannello.add(pannelloIcon);
        
    }
    
    
    public static void addPaddingButton(GridBagConstraints gbc, RoundedPanel2 rp){
        
        JPanel borderPanelContainer=new JPanel(new relativeMarginLayout(11.75f, 30f, 11.75f, 30f));
        borderPanelContainer.setOpaque(false);
        rp.add(borderPanelContainer,gbc);
        JPanel borderPanel= new JPanel();
        borderPanel.setBackground(new Color(166,166,166));
        borderPanelContainer.add(borderPanel);
        
    }
        
    public static void addChooseReceiverButton(GridBagConstraints gbc, RoundedPanel2 rp, MouseListener m, gui instance){
       
        JPanel scegliDestinatario = new JPanel();
        scegliDestinatario.setOpaque(false);
        rp.add(scegliDestinatario, gbc);
        scegliDestinatario.setLayout(new relativeMarginLayout(10f, 5f, 5f, 5f));
        ImagePanel scegliDestinatarioIcon= new ImagePanel("src/images/scegli_destinatario.png");
        wizardRollOverListner modificaRoll=new wizardRollOverListner(
                                                    "src/images/scegli_destinatario.png",
                                                    "src/images/scegli_destinatario.png",
                                                    "src/images/scegli_destinatario.png", instance, "Seleziona i destinatari e poi clicca qui");
        modificaRoll.setFrameParent(instance);
        scegliDestinatarioIcon.addMouseListener(modificaRoll);
        scegliDestinatarioIcon.addMouseListener(m);
        scegliDestinatarioIcon.setParent(rp);
        scegliDestinatario.add(scegliDestinatarioIcon);
        
    }
    
    public static void addInviaButton(GridBagConstraints gbc, RoundedPanel2 rp, MouseListener m, gui instance){
       
        JPanel invia = new JPanel();
        invia.setOpaque(false);
        rp.add(invia, gbc);
        invia.setLayout(new relativeMarginLayout(10f, 5f, 5f, 5f));
        ImagePanel inviaIcon= new ImagePanel("src/images/invia.png");
        wizardRollOverListner inviaRoll=new wizardRollOverListner(
                                                    "src/images/invia.png",
                                                    "src/images/invia.png",
                                                    "src/images/invia.png", instance, "Seleziona per inviare il messaggio");
        inviaRoll.setFrameParent(instance);
        inviaIcon.addMouseListener(inviaRoll);
        inviaIcon.addMouseListener(m);
        inviaIcon.setParent(rp);
        invia.add(inviaIcon);
        
    }
    
    public static void addDestinatarioButton(GridBagConstraints gbc, RoundedPanel2 rp, MouseListener m, gui instance){
       
        JPanel destinatario = new JPanel();
        destinatario.setOpaque(false);
        rp.add(destinatario, gbc);
        destinatario.setLayout(new relativeMarginLayout(10f, 5f, 5f, 5f));
        ImagePanel destinatarioIcon= new ImagePanel("src/images/destinatario.png");
        wizardRollOverListner destinatarioRoll=new wizardRollOverListner(
                                                    "src/images/destinatario.png",
                                                    "src/images/destinatario.png",
                                                    "src/images/destinatario.png", instance, "Seleziona per aggiungere altri destinatari");
        destinatarioRoll.setFrameParent(instance);
        destinatarioIcon.addMouseListener(destinatarioRoll);
        destinatarioIcon.addMouseListener(m);
        destinatarioIcon.setParent(rp);
        destinatario.add(destinatarioIcon);
        
    }
    
    public static void addFotoVideoButton(GridBagConstraints gbc, RoundedPanel2 rp, MouseListener m, gui instance){
       
        JPanel pannello = new JPanel();
        pannello.setOpaque(false);
        rp.add(pannello, gbc);
        pannello.setLayout(new relativeMarginLayout(10f, 5f, 5f, 5f));
        ImagePanel pannelloIcon= new ImagePanel("src/images/foto_video.png");
        wizardRollOverListner pannelloRoll=new wizardRollOverListner(
                                                    "src/images/foto_video.png",
                                                    "src/images/foto_video.png",
                                                    "src/images/foto_video.png", instance, "Seleziona per aggiungere foto o video");
        pannelloRoll.setFrameParent(instance);
        pannelloIcon.addMouseListener(pannelloRoll);
        pannelloIcon.addMouseListener(m);
        pannelloIcon.setParent(rp);
        pannello.add(pannelloIcon);
        
    }
    
    public static void addAggiungiContattoButton(GridBagConstraints gbc, RoundedPanel2 rp, MouseListener m, gui instance){
       
        JPanel pannello = new JPanel();
        pannello.setOpaque(false);
        rp.add(pannello, gbc);
        pannello.setLayout(new relativeMarginLayout(10f, 5f, 5f, 5f));
        ImagePanel pannelloIcon= new ImagePanel("src/images/aggiungi_contatto.png");
        wizardRollOverListner pannelloRoll=new wizardRollOverListner(
                                                    "src/images/aggiungi_contatto.png",
                                                    "src/images/aggiungi_contatto.png",
                                                    "src/images/aggiungi_contatto.png", instance, "Seleziona per aggiungere un nuovo contatto");
        pannelloRoll.setFrameParent(instance);
        pannelloIcon.addMouseListener(pannelloRoll);
        pannelloIcon.addMouseListener(m);
        pannelloIcon.setParent(rp);
        pannello.add(pannelloIcon);
        
    }
    
    public static void addVisualizzaBachecaButton(GridBagConstraints gbc, RoundedPanel2 rp, MouseListener m, gui instance){
       
        JPanel pannello = new JPanel();
        pannello.setOpaque(false);
        rp.add(pannello, gbc);
        pannello.setLayout(new relativeMarginLayout(10f, 5f, 5f, 5f));
        ImagePanel pannelloIcon= new ImagePanel("src/images/visualizza_bacheca.png");
        wizardRollOverListner pannelloRoll=new wizardRollOverListner(
                                                    "src/images/visualizza_bacheca.png",
                                                    "src/images/visualizza_bacheca.png",
                                                    "src/images/visualizza_bacheca.png", instance, "Seleziona per visualizzare la bacheca del contatto");
        pannelloRoll.setFrameParent(instance);
        pannelloIcon.addMouseListener(pannelloRoll);
        pannelloIcon.addMouseListener(m);
        pannelloIcon.setParent(rp);
        pannello.add(pannelloIcon);
        
    }
    
    public static void addDettagliButton(GridBagConstraints gbc, RoundedPanel2 rp, MouseListener m, gui instance){
       
        JPanel pannello = new JPanel();
        pannello.setOpaque(false);
        rp.add(pannello, gbc);
        pannello.setLayout(new relativeMarginLayout(10f, 5f, 5f, 5f));
        ImagePanel pannelloIcon= new ImagePanel("src/images/dettagli.png");
        wizardRollOverListner pannelloRoll=new wizardRollOverListner(
                                                    "src/images/dettagli.png",
                                                    "src/images/dettagli.png",
                                                    "src/images/dettagli.png", instance, "Seleziona per visualizzare i dettagli del contatto");
        pannelloRoll.setFrameParent(instance);
        pannelloIcon.addMouseListener(pannelloRoll);
        pannelloIcon.addMouseListener(m);
        pannelloIcon.setParent(rp);
        pannello.add(pannelloIcon);
        
    }
    
    public static void addInoltraMessaggioButton(GridBagConstraints gbc, RoundedPanel2 rp, MouseListener m, gui instance){
       
        JPanel pannello = new JPanel();
        pannello.setOpaque(false);
        rp.add(pannello, gbc);
        pannello.setLayout(new relativeMarginLayout(10f, 5f, 5f, 5f));
        ImagePanel pannelloIcon= new ImagePanel("src/images/inoltra.png");
        wizardRollOverListner pannelloRoll=new wizardRollOverListner(
                                                    "src/images/inoltra.png",
                                                    "src/images/inoltra.png",
                                                    "src/images/inoltra.png", instance, "Seleziona per inoltrare il messaggio");
        pannelloRoll.setFrameParent(instance);
        pannelloIcon.addMouseListener(pannelloRoll);
        pannelloIcon.addMouseListener(m);
        pannelloIcon.setParent(rp);
        pannello.add(pannelloIcon);
        
    }
    
    public static void addAscoltaMessaggioButton(GridBagConstraints gbc, RoundedPanel2 rp, MouseListener m, gui instance){
       
        JPanel pannello = new JPanel();
        pannello.setOpaque(false);
        rp.add(pannello, gbc);
        pannello.setLayout(new relativeMarginLayout(10f, 5f, 5f, 5f));
        ImagePanel pannelloIcon= new ImagePanel("src/images/ascolta.png");
        wizardRollOverListner pannelloRoll=new wizardRollOverListner(
                                                    "src/images/ascolta.png",
                                                    "src/images/ascolta.png",
                                                    "src/images/ascolta.png", instance, "Seleziona per riprodurre ed ascoltare il messaggio");
        pannelloRoll.setFrameParent(instance);
        pannelloIcon.addMouseListener(pannelloRoll);
        pannelloIcon.addMouseListener(m);
        pannelloIcon.setParent(rp);
        pannello.add(pannelloIcon);
        
    }
    
    public static void addRispondiMessaggioButton(GridBagConstraints gbc, RoundedPanel2 rp, MouseListener m, gui instance){
       
        JPanel pannello = new JPanel();
        pannello.setOpaque(false);
        rp.add(pannello, gbc);
        pannello.setLayout(new relativeMarginLayout(10f, 5f, 5f, 5f));
        ImagePanel pannelloIcon= new ImagePanel("src/images/rispondi_messaggio.png");
        wizardRollOverListner pannelloRoll=new wizardRollOverListner(
                                                    "src/images/rispondi_messaggio.png",
                                                    "src/images/rispondi_messaggio.png",
                                                    "src/images/rispondi_messaggio.png", instance, "Seleziona per rispondere a questo messaggio");
        pannelloRoll.setFrameParent(instance);
        pannelloIcon.addMouseListener(pannelloRoll);
        pannelloIcon.addMouseListener(m);
        pannelloIcon.setParent(rp);
        pannello.add(pannelloIcon);
        
    }
    
    public static void addEliminaMessaggioButton(GridBagConstraints gbc, RoundedPanel2 rp, MouseListener m, gui instance){
       
        JPanel pannello = new JPanel();
        pannello.setOpaque(false);
        rp.add(pannello, gbc);
        pannello.setLayout(new relativeMarginLayout(10f, 5f, 5f, 5f));
        ImagePanel pannelloIcon= new ImagePanel("src/images/elimina_messaggio.png");
        wizardRollOverListner pannelloRoll=new wizardRollOverListner(
                                                    "src/images/elimina_messaggio.png",
                                                    "src/images/elimina_messaggio.png",
                                                    "src/images/elimina_messaggio.png", instance, "Seleziona per eliminare il messaggio");
        pannelloRoll.setFrameParent(instance);
        pannelloIcon.addMouseListener(pannelloRoll);
        pannelloIcon.addMouseListener(m);
        pannelloIcon.setParent(rp);
        pannello.add(pannelloIcon);
        
    }
    
    public static void addScriviMessaggioButton(GridBagConstraints gbc, RoundedPanel2 rp, MouseListener m, gui instance){
       
        JPanel pannello = new JPanel();
        pannello.setOpaque(false);
        rp.add(pannello, gbc);
        pannello.setLayout(new relativeMarginLayout(10f, 5f, 5f, 5f));
        ImagePanel pannelloIcon= new ImagePanel("src/images/scrivi_messaggio.png");
        wizardRollOverListner pannelloRoll=new wizardRollOverListner(
                                                    "src/images/scrivi_messaggio.png",
                                                    "src/images/scrivi_messaggio.png",
                                                    "src/images/scrivi_messaggio.png", instance, "Seleziona per scrivere un messaggio al contatto");
        pannelloRoll.setFrameParent(instance);
        pannelloIcon.addMouseListener(pannelloRoll);
        pannelloIcon.addMouseListener(m);
        pannelloIcon.setParent(rp);
        pannello.add(pannelloIcon);
        
    }
    
}
